const mongoose = require("mongoose");

const noteSchema = new mongoose.Schema({
  title: { 
    type: String, 
    required: true, 
    trim: true 
  },
  content: { 
    type: String, 
    required: true,
    default: "" 
  },
  userId: { 
    type: mongoose.Schema.Types.ObjectId, 
    ref: 'User', 
    required: true 
  },
  createdAt: { 
    type: Date, 
    default: Date.now 
  },
  updatedAt: { 
    type: Date, 
    default: Date.now 
  }
}, {
  timestamps: true
});

// 创建索引以提高查询性能
noteSchema.index({ userId: 1, createdAt: -1 });
noteSchema.index({ title: 'text' }); // 标题搜索索引

module.exports = mongoose.model("Note", noteSchema);